<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="gv-forms" layout="column">
  <h1>Analytics</h1>
  <h2>Dashboards</h2>
  <div class="gv-form" ng-repeat="(type, dashboards) in $ctrl.dashboardsByType">
    <h3>{{type}}</h3>
    <div class="gv-form-content" layout="column">
      <md-table-container ng-if="dashboards.length > 0">
        <table md-table class="gv-table-dense">
          <thead md-head>
          <tr md-row>
            <th md-column class="column-with-logo">Name</th>
            <th permission permission-only="'environment-dashboard-u'" width="64px" nowrap></th>
            <th permission permission-only="'environment-dashboard-u'" width="48px" nowrap></th>
            <th permission permission-only="'environment-dashboard-u'" width="48px" nowrap></th>
            <th permission permission-only="'environment-dashboard-d'" width="48px" nowrap></th>
          </tr>
          </thead>
          <tbody md-body>
          <tr md-row ng-repeat="dashboard in dashboards">
            <td md-cell permission permission-only="'environment-dashboard-u'">
              <a ng-style="dashboard.enabled?'':{'font-style': 'italic', 'color': 'grey'}"
                 ui-sref="management.settings.dashboard({type: type, dashboardId: dashboard.id})">{{dashboard.name}}</a>
            </td>
            <td md-cell permission permission-except="'environment-dashboard-u'">
              <span ng-style="dashboard.enabled?'':{'font-style': 'italic', 'color': 'grey'}">{{dashboard.name}}</span>
            </td>
            <td md-cell width="48px">
              <ng-md-icon ng-if="!dashboard.enabled" icon="not_interested" ng-click="$ctrl.toggleEnable(dashboard)"
                          style="font-size: 24px; height: 24px;"
                          permission permission-only="'environment-dashboard-u'">
                <md-tooltip md-direction="top" md-visible="false">Enable this dashboard</md-tooltip>
              </ng-md-icon>
              <ng-md-icon ng-if="dashboard.enabled" icon="done" ng-click="$ctrl.toggleEnable(dashboard)"
                          style="font-size: 24px; height: 24px;"
                          permission permission-only="'environment-dashboard-u'">
                <md-tooltip md-direction="top" md-visible="false">Disable this dashboard</md-tooltip>
              </ng-md-icon>
            </td>
            <td md-cell permission permission-only="'environment-dashboard-u'" width="76px" nowrap>
              <ng-md-icon ng-if="!$first" icon="arrow_upwards" ng-click="$ctrl.upward(dashboard)">
                <md-tooltip md-direction="top" md-visible="false">Move upward</md-tooltip>
              </ng-md-icon>
              <span ng-if="$first" style="padding-right: 28px"></span>
              <ng-md-icon ng-if="!$last" icon="arrow_downward" ng-click="$ctrl.downward(dashboard)">
                <md-tooltip md-direction="top" md-visible="false">Move downward</md-tooltip>
              </ng-md-icon>
            </td>
            <td md-cell permission permission-only="'environment-dashboard-d'">
              <ng-md-icon icon="delete" ng-click="$ctrl.delete(dashboard)"></ng-md-icon>
            </td>
          </tr>
          </tbody>
        </table>
      </md-table-container>
      <gravitee-empty-state ng-if="dashboards.length === 0"
                            icon="insert_chart"
                            model="Dashboard"
                            message="Dashboards will appear here"
                            sub-message="Start creating a dashboard"
                            create-mode="true"></gravitee-empty-state>
      <div class="md-actions gravitee-api-save-button" layout="row">
        <md-button permission permission-only="'environment-dashboard-c'"
                   aria-label="Add dashboard {{type}}"
                   ui-sref="management.settings.dashboardnew({type: type})"
                   class="md-raised md-primary">
          Add a new dashboard {{type}}
        </md-button>
      </div>
    </div>
  </div>
  <h2>Settings</h2>
  <div class="gv-form">
    <form name="$ctrl.formSettings" class="gv-form-content" layout="column" ng-submit="$ctrl.save()">
      <md-input-container class="md-block" flex-gt-sm>
        <label>HTTP Client Timeout</label>
        <input type="number" min="0" ng-model="$ctrl.settings.analytics.clientTimeout">
      </md-input-container>

      <md-card-actions>
        <md-button type="submit" class="md-raised md-primary" ng-disabled="$ctrl.formSettings.$invalid || $ctrl.formSettings.$pristine"
                   permission permission-only="['environment-settings-c', 'environment-settings-u', 'environment-settings-d']">Save</md-button>
        <md-button type="button" class="md-raised" ng-click="$ctrl.reset()" ng-disabled="$ctrl.formSettings.$invalid || $ctrl.formSettings.$pristine"
                   permission permission-only="['environment-settings-c', 'environment-settings-u', 'environment-settings-d']">Reset</md-button>
      </md-card-actions>
    </form>
  </div>
</div>
